feat: validate message_length_limit is non-negative#1916
Open
SARAMALI15792 wants to merge 1 commit intocommitizen-tools:masterfrom
Open
feat: validate message_length_limit is non-negative#1916SARAMALI15792 wants to merge 1 commit intocommitizen-tools:masterfrom
SARAMALI15792 wants to merge 1 commit intocommitizen-tools:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1916 +/- ##
=======================================
Coverage 97.99% 97.99%
=======================================
Files 60 60
Lines 2689 2695 +6
=======================================
+ Hits 2635 2641 +6
Misses 54 54 ☔ View full report in Codecov by Sentry. |
Add validation to ensure message_length_limit is a non-negative integer (>= 0). Negative values now raise InvalidCommandArgumentError instead of being treated as "no limit". Changes: - Add validation in Check and Commit __init__ to reject negative values - Change condition from `<= 0` to `== 0` for "no limit" check - Update CommitArgs and CheckArgs to accept int | None for CLI override - Add comprehensive test coverage for negative value rejection - Update documentation to clarify non-negative requirement Behavior: - message_length_limit < 0: raises InvalidCommandArgumentError - message_length_limit = 0: disables length limit (no limit) - message_length_limit > 0: enforces the specified limit - CLI None value: falls back to config setting Fixes commitizen-tools#1909 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
100df54 to
fdcdaec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Added validation for
message_length_limitto ensure it accepts only non-negative integers (>= 0). Negative values now raiseInvalidCommandArgumentErrorinstead of being silently treated as "no limit".This PR addresses the inconsistency identified in #1909 where negative values were accepted but had unclear behavior.
Root Cause
After the fix in #1813 changed the default from
Noneto0for "no limit", the validation logic still checked<= 0instead of== 0. This meant:message_length_limit = 0→ no limit ✅ (intended)message_length_limit = -1→ no limit ✅ (unintended, should error)Changes
CheckandCommit__init__to rejectmessage_length_limit < 0<= 0to== 0for "no limit" checkCommitArgsandCheckArgsto acceptint | Nonefor proper CLI override handlingdocs/config/check.mdanddocs/config/commit.mdto clarify non-negative requirementWhy This Is Safe
0(no limit), so existing configs without this setting are unaffected0(same effect, clearer intent)0means "no limit"Expected Behavior
message_length_limit < 0→ raisesInvalidCommandArgumentError❌message_length_limit = 0→ disables length limit ✅message_length_limit > 0→ enforces the specified limit ✅Nonevalue → falls back to config setting ✅Steps to Test This Pull Request
Checklist
uv run poe alllocally to ensure this change passes linter check and testsRelated
message_length_limitis non-negative #1908 (similar approach, independent implementation)0as "no limit")